<template>
  <div class="app-container">
    <div class="filter-container">
      <el-cascader
          v-if="level == 1"
          class="filter-item"
          v-model="selectParent" :options="distributorsList"
          :props="distributorsProps"
          placeholder="所属经销商"
          @change="getList"
          style="width: 15%" clearable filterable></el-cascader>

      <el-select v-model="listQuery.station_id" filterable placeholder="请选择电站" class="filter-item" clearable
                 @change="getList" style="width: 10%;margin-left:10px"
      >
        <el-option
            v-for="item in stationList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
        >
        </el-option>
      </el-select>
      <el-input
          class="filter-item"
          placeholder="设备号范围(小)"
          v-model="listQuery.min_sn"
          style="width: 10%;margin-left: 5px"
          @keyup.enter.native="getList"
      >
      </el-input>
      <el-input
          class="filter-item"
          placeholder="设备号范围(大)"
          v-model="listQuery.max_sn"
          style="width: 10%;"
          @keyup.enter.native="getList"
      >
      </el-input>
      <!--      <el-input v-model="listQuery.title" placeholder="Title" style="width: 200px;" class="filter-item"-->
      <!--                @keyup.enter.native="handleFilter"-->
      <!--      />-->
      <!--      <el-select v-model="listQuery.importance" placeholder="Imp" clearable style="width: 90px" class="filter-item">-->
      <!--        <el-option v-for="item in importanceOptions" :key="item" :label="item" :value="item" />-->
      <!--      </el-select>-->
      <!--      <el-select v-model="listQuery.type" placeholder="Type" clearable class="filter-item" style="width: 130px">-->
      <!--        <el-option v-for="item in calendarTypeOptions" :key="item.key" :label="item.display_name+'('+item.key+')'" :value="item.key" />-->
      <!--      </el-select>-->
      <!--      <el-select v-model="listQuery.sort" style="width: 140px" class="filter-item" @change="handleFilter">-->
      <!--        <el-option v-for="item in sortOptions" :key="item.key" :label="item.label" :value="item.key" />-->
      <!--      </el-select>-->
      <el-radio-group v-model="listQuery.is_active" style="margin-left: 5px" class="filter-item" @change="getList">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button :label="1">正常</el-radio-button>
        <el-radio-button :label="0">冻结</el-radio-button>
      </el-radio-group>


      <el-upload
          style="float: right;margin-right:10px;margin-top:5px"
          class="upload-demo"
          ref="upload"
          :action="'/api/device/batch_create?distributor_id='+selectParent+'&is_new='+listQuery.is_new"
          :on-preview="handlePreview"
          :on-remove="handleRemove"
          :on-success="excelSuccess"
          :before-remove="beforeRemove"
          multiple
          :limit="10"
          :on-exceed="handleExceed"
          :auto-upload="false"
      >
        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
        <el-button style="margin-left: 10px;" size="small" type="success" @click="submitUpload">上传到服务器</el-button>
      </el-upload>
      <br/>
      <el-date-picker
          class="filter-item"
          v-model="listQuery.time"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          :picker-options="pickerOptions"
          range-separator="至"
          start-placeholder="注册时间范围(小)"
          end-placeholder="注册时间范围(大)"
          @change="getList"
          align="right"
      >
      </el-date-picker>
      <el-input
          class="filter-item"
          placeholder="设备号搜索"
          v-model="listQuery.sn"
          style="width: 10%;margin-left: 5px"
          @keyup.enter.native="getList"
      >
      </el-input>
      <el-input
          class="filter-item"
          placeholder="物联网搜索"
          v-model="listQuery.iot_sn"
          style="width: 10%;margin-left: 5px"
          @keyup.enter.native="getList"
      >
      </el-input>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getList"
                 style="margin-left: 10px"
      >
        搜索
      </el-button>
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit"
                 @click="handleCreate"
      >
        添加
      </el-button>
      <el-radio-group v-model="listQuery.inline" size="mini" style="margin-left: 5px" class="filter-item" @change="getList">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button :label="1">在线</el-radio-button>
        <el-radio-button :label="0">离线</el-radio-button>
      </el-radio-group>

      <el-radio-group v-model="listQuery.is_refund" size="mini" style="margin-left: 5px" class="filter-item" @change="getList">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button :label="1">支持退款</el-radio-button>
        <el-radio-button :label="0">不支持退款</el-radio-button>
      </el-radio-group>

      <el-radio-group v-model="listQuery.is_new" size="mini" style="margin-left: 5px" class="filter-item" @change="getList">
        <el-radio-button label="">全部</el-radio-button>
        <el-radio-button :label="0">老设备</el-radio-button>
        <el-radio-button :label="1">新设备</el-radio-button>
      </el-radio-group>

      <!--      <el-button v-waves :loading="downloadLoading" class="filter-item" type="primary" icon="el-icon-download"-->
      <!--                 @click="handleDownload"-->
      <!--      >-->
      <!--        导出-->
      <!--      </el-button>-->
      <!--      <el-checkbox v-model="showReviewer" class="filter-item" style="margin-left:15px;" @change="tableKey=tableKey+1">-->
      <!--        审核-->
      <!--      </el-checkbox>-->
    </div>
    <el-checkbox-group v-model="checkedIds" @change="handleCheckedIdsChange">
      <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
        <el-table-column align="center" label="ID" min-width="80">
          <template slot-scope="scope">
            <el-checkbox :key="scope.row.id" :label="scope.row.id"
            ></el-checkbox>
          </template>
        </el-table-column>
        <el-table-column min-width="80" align="center" label="设备号">
          <template slot-scope="scope">
            <el-link type="primary">{{ scope.row.sn }}</el-link>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>
        <el-table-column min-width="80" align="center" label="物联网编号">
          <template slot-scope="scope">
            <el-link type="success">{{ scope.row.iot_sn }}</el-link>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>


        <el-table-column min-width="80" align="center" label="卡号">
          <template slot-scope="scope">
            <span>{{ scope.row.card_no }}</span>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>

        <el-table-column min-width="60" align="center" label="经销商">
          <template slot-scope="scope">
          <span v-if="scope.row.distributor_name">
             <router-link :to="'/distributors/list?keyword='+scope.row.distributor_name" class="link-type">
              <el-link type="primary">{{ scope.row.distributor_name }}</el-link>
          </router-link>
          </span>
            <span v-else>无</span>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>

        <el-table-column min-width="60" align="center" label="通道数">
          <template slot-scope="scope">
            <span>{{ scope.row.channel }}</span>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>

        <el-table-column min-width="60" align="center" label="二维码">
          <template slot-scope="scope">
            <el-button type="success" size="mini" @click="showQr(scope.row)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column min-width="80" align="center" label="绑定站点">
          <template slot-scope="scope">
            <span v-if="scope.row.station">{{ scope.row.station.name }}</span>
            <span v-else>未绑定</span>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>

        <el-table-column min-width="80" align="center" label="套餐">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="showCharge(scope.row.charge_id)">查看</el-button>
          </template>
        </el-table-column>

        <el-table-column min-width="50" align="center" label="在线">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="查看最近上报" placement="top-start">
              <el-link type="success" v-if="scope.row.inline === 1" @click="signalList(scope.row)">在线</el-link>
              <el-link type="info" @click="signalList(scope.row)" v-else>离线</el-link>
              <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column min-width="50" align="center" label="类型">
          <template slot-scope="scope">
              <el-link type="success" v-if="scope.row.is_new === 1" >新</el-link>
              <el-link type="info" v-else>老</el-link>
              <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>


        <el-table-column min-width="60" align="center" label="信号">
          <template slot-scope="scope">
            <span>{{ scope.row.signal }}</span>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>
        <el-table-column min-width="50" align="center" label="累计收益">
          <template slot-scope="scope">
            <el-link type="success">{{ scope.row.profit }}</el-link>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>
        <el-table-column min-width="50" align="center" label="当月订单">
          <template slot-scope="scope">
            <el-link type="success">{{ scope.row.orders_count }}</el-link>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>
        <el-table-column min-width="80" align="center" label="备注">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" :content="scope.row.remark" placement="top">
              <span>{{ scope.row.remark | ellipsis }}</span>
            </el-tooltip>
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>
        <el-table-column min-width="80" align="center" label="最后在线时间">
          <template slot-scope="scope">
            {{ scope.row.last_online_at }}
            <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
          </template>
        </el-table-column>
<!--        <el-table-column min-width="120" align="center" label="当前套餐">-->
<!--          <template slot-scope="scope">-->
<!--            <el-button type="success" size="mini" v-if="scope.row.charge_id"-->
<!--                       @click="showCharge(scope.row.charge_id)">-->
<!--              {{ scope.row.charge_name }}-->
<!--            </el-button>-->
<!--            <el-button type="success" size="mini" v-else-->
<!--                       @click="showCharge(scope.row.charge_id)">-->
<!--              默认平台套餐-->
<!--            </el-button>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column min-width="55" align="center" label="状态">
          <template slot-scope="scope">
            <el-switch
                v-model="scope.row.is_active"
                :active-value="1"
                :inactive-value="0"
                @change="changeStatus($event,scope.row.id)"

            >
            </el-switch>
          </template>
        </el-table-column>
        <el-table-column min-width="80" align="center" label="创建时间">
          <template slot-scope="scope">
            <span>{{ scope.row.created_at }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" min-width="220" fixed="right">
          <template slot-scope="scope">
            <el-dropdown style="margin-left:5px" size="mini" @command="handleCommand" split-button type="primary"
                         @click="handleUpdate(scope.row)">
              编辑
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item :command="{'row': scope.row, 'type': 'showPort'}">最近端口状态</el-dropdown-item>
                <el-dropdown-item :command="{'row': scope.row, 'type': 'reset'}">复位</el-dropdown-item>
                <el-dropdown-item :command="{'row': scope.row, 'type': 'readParams'}">读取配置</el-dropdown-item>
                <el-dropdown-item :command="{'row': scope.row, 'type': 'updateParams'}">修改配置</el-dropdown-item>
                <el-dropdown-item :command="{'row': scope.row, 'type': 'unbind'}">恢复出厂设置</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <el-button type="danger" size="mini" icon="el-icon-delete" style="margin-left:5px"
                       @click="del(scope.row.id)">
            </el-button>
            <el-button type="success" size="mini" style="margin-left:5px"
                       @click="updateVersion(scope.row)">
              升级
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-checkbox-group>
    <el-divider>
      <el-checkbox :indeterminate="isIndeterminate" style="margin-left:10px;" v-model="checkAll"
                   @change="handleCheckAllChange"
      >全选
      </el-checkbox>
      <el-button type="primary" size="mini" round style="margin-left:10px;" @click="batchShow">批量修改</el-button>
    </el-divider>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                @pagination="getList"
    />

    <el-dialog title="批量修改经销商" :visible.sync="dialogBatchVisible" width="50%">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="120px"
               style="width: 90%; margin-left:5%;"
      >
        <el-form-item label="上级经销商">
          <el-cascader v-model="batch_distributor_id" :options="distributorsList"
                       :props="distributorsProps"
                       placeholder="不选择则为自身设备"
                       style="width: 80%" clearable filterable></el-cascader>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <center>
          <el-button type="primary" @click="batchChange()">
            提交
          </el-button>
        </center>
      </div>
    </el-dialog>


    <el-dialog :title="'套餐名称：'+now_charge.name" :visible.sync="showChargeVisible" width="50%">
      <el-descriptions title="套餐信息" border>
        <el-descriptions-item label="套餐类型" v-if="now_charge.type == 3">电量套餐</el-descriptions-item>
        <el-descriptions-item label="套餐类型" v-else>常规套餐</el-descriptions-item>
        <el-descriptions-item label="充满自停">{{ now_charge.is_autoload == 1 ? '开' : '关' }}</el-descriptions-item>
        <el-descriptions-item label="充满自停金额">{{ now_charge.fee }}</el-descriptions-item>
        <el-descriptions-item label="最低消费金额">{{ now_charge.pre_fee }}/元</el-descriptions-item>
        <el-descriptions-item label="服务单价" v-if="now_charge.type == 3">{{ now_charge.service_fee }}/元
        </el-descriptions-item>
        <el-descriptions-item label="收取类型" v-if="now_charge.type == 3">
          {{ now_charge.service_type == 1 ? '每度' : '每小时' }}
        </el-descriptions-item>
        <el-descriptions-item label="电价/每度" v-if="now_charge.type == 3">{{ now_charge.elec_price }}元
        </el-descriptions-item>
        <el-descriptions-item label="最大充电量" v-if="now_charge.type == 3">{{ now_charge.elec }}
        </el-descriptions-item>
      </el-descriptions>
      <el-card v-if="now_charge.type != 3">
        <el-divider>功率选项</el-divider>
        <div v-for="item in now_charge.power_children">
          <el-descriptions :column="2" border>
            <el-descriptions-item label="每元分钟数">{{ item.minutes }}</el-descriptions-item>
            <el-descriptions-item label="功率范围/W ">{{ item.min_power }}W至{{
                item.max_power
              }}W
            </el-descriptions-item>
            <el-descriptions-item label="生效时间">{{ item.created_at }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <el-divider>时间选项</el-divider>
        <div v-for="item in now_charge.time_children">
          <el-descriptions border>
            <el-descriptions-item label="总分钟数">{{ item.minutes }}</el-descriptions-item>
            <el-descriptions-item label="金额">{{ item.fee }}</el-descriptions-item>
            <el-descriptions-item label="生效时间">{{ item.created_at }}</el-descriptions-item>
          </el-descriptions>
        </div>
      </el-card>
      <el-card v-else>
        <el-divider>电量选项</el-divider>
        <div v-for="item in now_charge.elec_children">
          <el-descriptions border>
            <el-descriptions-item label="金额">{{ item.fee }}</el-descriptions-item>
            <el-descriptions-item label="生效时间">{{ item.created_at }}</el-descriptions-item>
          </el-descriptions>
        </div>
        <el-divider>服务费档位</el-divider>
        <div v-for="item in now_charge.service_children">
          <el-descriptions border>
            <el-descriptions-item label="功率范围/W ">{{ item.min_power }}W至{{ item.max_power }}W</el-descriptions-item>
            <el-descriptions-item label="元/每小时">{{ item.fee }}</el-descriptions-item>
            <el-descriptions-item label="生效时间">{{ item.created_at }}</el-descriptions-item>
          </el-descriptions>
        </div>
      </el-card>
    </el-dialog>

    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" width="60%">
      <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="120px"
               style="width: 90%; margin-left:5%;"
      >
        <el-form-item label="上级经销商"  v-if="level == 1">
          <el-cascader v-model="edit_distributor_id" ref="cascaderDistributors" :options="distributorsList"
                       :props="distributorsProps"
                       placeholder="不选择则为一级"
                       @change="handleDistributorsChange"
                       style="width: 80%" clearable filterable></el-cascader>
        </el-form-item>
        <el-form-item label="选择电站">
          <el-select v-model="temp.station_id" filterable placeholder="请选择电站" clearable
                     style="width: 80%;"
          >
            <el-option
                v-for="item in stationList1"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="选择套餐">
          <el-select v-model="temp.charge_id" filterable placeholder="请选择套餐" clearable
                     style="width: 80%;"
          >
            <el-option
                v-for="item in chargeList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="备注">
          <el-input v-model="temp.remark" style="width: 80%"/>
        </el-form-item>

        <el-row :gutter="32">
          <el-col :xs="24" :sm="24" :lg="13">
            <el-card>
              <el-form-item label="设备编号" prop="sn">
                <el-input v-model="temp.sn" :disabled="dialogStatus == 'update'?true:false"/>
              </el-form-item>
              <el-form-item label="物联网编号" prop="iot_sn">
                <el-input v-model="temp.iot_sn"/>
              </el-form-item>
              <el-form-item label="通道数量" prop="channel">
                <el-input v-model="temp.channel" type="number"/>
              </el-form-item>
              <el-form-item label="设备类型">
              <el-radio-group v-model="temp.is_new" size="small">
                <el-radio-button :label="1">新设备</el-radio-button>
                <el-radio-button :label="0">老设备</el-radio-button>
              </el-radio-group>
              </el-form-item>
            </el-card>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="11">
            <el-card>
              <!---->
              <el-form-item label="是否支持退款">
                <el-radio-group v-model="temp.is_refund" size="small">
                  <el-radio-button :label="1">是</el-radio-button>
                  <el-radio-button :label="0">否</el-radio-button>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="状态">
                <el-switch
                    v-model="temp.is_active"
                    :active-value="1"
                    :inactive-value="0"
                    active-text="开启"
                    inactive-text="关闭">
                </el-switch>
              </el-form-item>
              <el-form-item label="安心充">
                <el-radio-group v-model="temp.is_service" size="small">
                  <el-radio-button :label="0">隐藏</el-radio-button>
                  <el-radio-button :label="1">展示</el-radio-button>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="线损/百分比">
                 <el-input v-model="temp.speed"/>
              </el-form-item>
            </el-card>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <center>
          <el-button @click="resetForm">
            取消
          </el-button>
          <el-button type="primary" @click="dialogStatus==='create'?createData():createData()">
            提交
          </el-button>
        </center>
      </div>
    </el-dialog>


    <el-dialog title="设备参数修改" :visible.sync="dialogParamsVisible" width="60%">
      <el-form ref="dataForm" :model="paramsTemp" label-position="left" label-width="220px"
               style="width: 90%; margin-left:5%;"
      >

        <el-row :gutter="32">
          <el-col :xs="24" :sm="24" :lg="12">
            <el-card>
              <el-divider><font color="#ccc" size="2">基础信息</font></el-divider>
              <el-form-item label="设备编号" prop="sn">
                <el-input v-model="paramsTemp.sn" :disabled="true"/>
              </el-form-item>
              <el-form-item label="物联网编号" prop="sn">
                <el-input v-model="paramsTemp.iot_sn" :disabled="true"/>
              </el-form-item>
              <el-form-item label="投币充电时间(单位为分钟)">
                <el-input v-model="paramsTemp.coin_min" type="number"/>
              </el-form-item>
              <el-form-item label="刷卡充电时间(单位为分钟)">
                <el-input v-model="paramsTemp.card_min" type="number"/>
              </el-form-item>
              <el-form-item label="单次投币最大电量(单位为0.1度)">
                <el-input v-model="paramsTemp.coin_elec" type="number"/>
              </el-form-item>
              <el-form-item label="单次刷卡最大电量(单位为0.1度)">
                <el-input v-model="paramsTemp.card_elec" type="number"/>
              </el-form-item>
              <el-form-item label="刷卡扣费金额(单位为角)">
                <el-input v-model="paramsTemp.cst" type="number"/>
              </el-form-item>
              <el-form-item label="最大浮冲功率(单位为瓦)">
                <el-input v-model="paramsTemp.full_power_min" type="number"/>
              </el-form-item>
              <el-form-item label="浮冲时间(单位为分钟)">
                <el-input v-model="paramsTemp.full_charge_time" type="number"/>
              </el-form-item>
            </el-card>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="12">
            <el-card>
              <el-form-item label="第1档最大充电功率(单位为瓦)">
                <el-input v-model="paramsTemp.power_max_1" type="number"/>
              </el-form-item>
              <el-form-item label="第2档最大充电功率(单位为瓦)">
                <el-input v-model="paramsTemp.power_max_2" type="number"/>
              </el-form-item>
              <el-form-item label="第3档最大充电功率(单位为瓦)">
                <el-input v-model="paramsTemp.power_max_3" type="number"/>
              </el-form-item>
              <el-form-item label="第4档最大充电功率(单位为瓦)">
                <el-input v-model="paramsTemp.power_max_4" type="number"/>
              </el-form-item>
              <el-form-item label="第2档充电时间百分比">
                <el-input v-model="paramsTemp.power_2_time" type="number"/>
              </el-form-item>
              <el-form-item label="第3档充电时间百分比">
                <el-input v-model="paramsTemp.power_3_time" type="number"/>
              </el-form-item>
              <el-form-item label="第4档充电时间百分比">
                <el-input v-model="paramsTemp.power_4_time" type="number"/>
              </el-form-item>
              <el-form-item label="是否支持余额回收">
                <el-radio-group v-model="paramsTemp.sp_rec_mon" size="small">
                  <el-radio-button :label="1">是</el-radio-button>
                  <el-radio-button :label="0">否</el-radio-button>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="是否支持断点自停">
                <el-radio-group v-model="paramsTemp.sp_full_empty" size="small">
                  <el-radio-button :label="1">是</el-radio-button>
                  <el-radio-button :label="0">否</el-radio-button>
                </el-radio-group>
              </el-form-item>
              <el-form-item label="是否初始显示剩余电量">
                <el-radio-group v-model="paramsTemp.elec_time_first" size="small">
                  <el-radio-button :label="1">是</el-radio-button>
                  <el-radio-button :label="0">否</el-radio-button>
                </el-radio-group>
              </el-form-item>
            </el-card>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <center>
          <el-button @click="resetParams">
            取消
          </el-button>
          <el-button type="primary" @click="submitParams">
            提交
          </el-button>
        </center>
      </div>
    </el-dialog>


    <el-drawer
        :title="'查看设备'+now_port_sn+'端口最近状态'"
        :visible.sync="portDrawer"
    >
      <el-card v-if="now_port_status.length !== 0">
        <el-card style="margin:3px" v-for="item in now_port_status">
          <el-descriptions class="margin-top" :column="3" size="mini" border>
            <!--        <template slot="extra">-->
            <!--          <el-button type="primary" size="small">操作</el-button>-->
            <!--        </template>-->
            <el-descriptions-item>
              <template slot="label">
                端口号
              </template>
              {{ item.number }}
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                功率/W
              </template>
              {{ item.power }}W
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                状态
              </template>
              <el-tag v-if="item.status == 2" type="primary">使用中</el-tag>
              <el-tag v-else type="success">空闲</el-tag>
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                剩余时间
              </template>
              {{ item.time }}分钟
            </el-descriptions-item>
            <el-descriptions-item>
              <template slot="label">
                剩余电量/度
              </template>
              <span>{{ item.electric_quantity }}度</span>
              <el-button type="primary" style="margin-left: 40px" plain size="mini" @click="startPort(item.number)">操作
              </el-button>

            </el-descriptions-item>

          </el-descriptions>
        </el-card>
      </el-card>
      <el-card v-else>
        <el-empty description="设备暂未上报过端口状态"></el-empty>
      </el-card>
    </el-drawer>


    <el-dialog :title="'设备'+now_port_sn+'开启端口'+now_submit_port" :visible.sync="dialogPortVisible" width="30%">
      <el-form :rules="rules" :model="temp" label-position="left" label-width="120px"
               style="width: 90%; margin-left:5%;"
      >
        <el-card>
          <el-form-item label="时长">
            <el-input v-model="portTemp.minutes" type="number"/>
          </el-form-item>
          <el-form-item label="费用">
            <el-input v-model="portTemp.fee" type="number"/>
          </el-form-item>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <center>
          <el-button @click="resetPort">
            取消
          </el-button>
          <el-button type="primary" @click="submitPort">
            提交
          </el-button>
        </center>
      </div>
    </el-dialog>


    <el-drawer
        :title="'设备'+now_sn+'最近20条信号记录'"
        :visible.sync="signalDraw"
    >
      <template>
        <el-card>
          <el-table
              stripe
              :data="signalData"
              style="width: 100%">
            <el-table-column
                prop="signal"
                label="信号值"
                width="80">
            </el-table-column>
            <el-table-column
                prop="created_at"
                label="上报时间"
                width="180">
            </el-table-column>
          </el-table>
        </el-card>
      </template>
    </el-drawer>

    <el-dialog :title="'设备号------'+now_sn" :visible.sync="dialogImgVisible">
      <el-row :gutter="32">
        <el-col>
          <el-radio-group v-model="now_port" @change="getPortImg"
                          style="float:right;margin-right:10px;margin-bottom: 30px">
            <el-radio-button v-for="index in now_chanel" :label="index"></el-radio-button>
          </el-radio-group>
        </el-col>
        <el-col :xs="24" :sm="24" :lg="12">
          <el-card>
            <center><span><font color="#ccc">设备码</font></span></center>
            <center>
              <el-image :src="sn_image"></el-image>
            </center>
          </el-card>
        </el-col>

        <el-col :xs="24" :sm="24" :lg="12">
          <el-card>
            <center><span><font color="#ccc">端口码</font></span></center>
            <center>
              <el-image :src="port_image"></el-image>
            </center>
          </el-card>
        </el-col>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import {
  getList,
  create,
  del,
  changeStatus,
  getQrImg,
  reset,
  readParams,
  batchChange,
  startPort,
  updateParams,
  chargeDetail,
  signalList,
    unbind,
    updateUrl,
    getCharge
} from '@/api/device'
import {selectStation, getDistributor} from '@/api/station'
// import { getMenus } from '@/api/menu'
import Pagination from '@/components/Pagination'
import store from '@/store'
import router from '@/router' // Secondary package based on el-pagination
import ImageCropper from '@/components/ImageCropper'
import PanThumb from '@/components/PanThumb'
import cityData from '@/assets/pca-code.json'
import {all} from "@/api/distributors";
import {selectCharge} from "@/api/station";
import {refundNormal} from "@/api/order";

export default {
  name: 'DeviceList',
  components: {Pagination, ImageCropper, PanThumb},
  computed: {
    // contentShortLength() {
    //   return this.temp.introduction .length
    // },
  },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    },
    ellipsis(value) {
      if (!value) return ''
      if (value.length > 12) {
        return value.slice(0, 12) + '...'
      }
      return value
    }
  },
  data() {
    return {
      info: [],
      dialogBatchVisible: false,
      dialogParamsVisible: false,
      dialogPortVisible: false,
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
            picker.$emit('pick', [start, end])
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date()
            const start = new Date()
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
            picker.$emit('pick', [start, end])
          }
        }]
      },
      checkAll: false,
      idOptions: [],
      isIndeterminate: true,
      checkedIds: [],
      edit_distributor_id: [],
      stationList1: [],
      stationList: [],
      now_sn: '',
      chargeList:[],
      now_chanel: '',
      now_port: 1,
      now_port_sn: '',
      now_submit_port: '',
      sn_image: '',
      port_image: '',
      dialogImgVisible: false,
      imagecropperShow: false,
      imagecropperKey: 0,
      menus: [],
      roles: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        min_sn: '',
        max_sn: '',
        time: [],
        distributor_id: '',
        is_active: '',
        station_id: '',
        inline: '',
        is_refund: '',
        is_disabled: '',
        is_new:'',
        iot_sn:''
      },
      showChargeVisible: false,
      selectAreas: '',
      selectParent: '',
      temp: {
        id: undefined,
        sn: '',
        iot_sn: '',
        channel: '',
        station_id: '',
        is_refund: 0,
        distributors: '',
        // is_fault:0,
        remark: '',
        is_active: 1,
        is_new: 0,
        is_disabled: 0,
        is_service: 1,
        speed:100,
        charge_id:''
      },
      portTemp: {
        sn: '',
        port: '',
        minutes: 0,
        fee: 0
      },
      signalDraw: false,
      now_port_status: [],
      paramsTemp: {
        sn: '',
        iot_sn: '',
        coin_min: 0,
        card_min: 0,
        coin_elec: 0,
        card_elec: 0,
        cst: 0,
        power_max_1: 0,
        power_max_2: 0,
        power_max_3: 0,
        power_max_4: 0,
        power_2_time: 0,
        power_3_time: 0,
        power_4_time: 0,
        sp_rec_mon: 1,
        sp_full_empty: 1,
        full_power_min: 0,
        full_charge_time: 0,
        elec_time_first: 1
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      portDrawer: false,
      filterText: '',
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      rules: {
        sn: [{required: true, message: '设备编号不能为空', trigger: 'blur'}],
        iot_sn: [{required: true, message: '物联网编号不能为空', trigger: 'blur'}],
        channel: [{required: true, message: '请输入通道数量', trigger: 'blur'}]
      },
      addr: [],
      options: cityData,
      distributorsList: [],
      batch_distributor_id: '',
      nowDistributor: '',
      disOptions: [],
      level:'',
      cityProps: {
        value: 'code',   // 指定选项的 值 为选项对象的某个属性值
        label: 'name',   // 指定选项 标签 为选项对象的某个属性值
        children: 'children'    //指定选项的 子选项 为选项对象的某个属性值
      },
      colors: [
        {color: '#f56c6c', percentage: 20},
        {color: '#e6a23c', percentage: 40},
        {color: '#5cb87a', percentage: 60},
        {color: '#1989fa', percentage: 80},
        {color: '#6f7ad3', percentage: 100}
      ],
      now_charge: [],
      distributorsProps: {
        value: 'id',
        label: 'name',
        children: 'children',
        checkStrictly: true
      },
      selectCityProps: {
        value: 'code',   // 指定选项的 值 为选项对象的某个属性值
        label: 'name',   // 指定选项 标签 为选项对象的某个属性值
        children: 'children',    //指定选项的 子选项 为选项对象的某个属性值
        checkStrictly: true
      },
      signalData: []
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  mounted() {

  },
  created() {
    this.level = this.$store.getters.introduction
    this.getSelector()
    let station_id = this.$route.query.station_id
    if (station_id) {
      this.listDistributor(station_id)
      this.listQuery.station_id = +station_id
    }
    let distributor_id = this.$route.query.distributor_id
    if (distributor_id) {
      this.selectParent = +distributor_id
    }
    this.getList()
    this.getCharge()
    // if(station_id){
    //   setTimeout(() => {
    //     this.listQuery.station_id = station_id
    //   }, 2000);
    // }
  },
  methods: {
    getCharge(){
      getCharge().then(response=>{
          this.chargeList = response.data
      })
    },
    updateVersion(row){
      if(row.is_new != 1){
        this.$message.info('仅可升级新设备')
        return
      }
      if(row.channel == 10){
        this.$prompt('固件路径', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputValue: '/device/eBIKE-ML307R-P10-Upgradev1.01.024.bin'
        }).then(({value}) => {
          // if(value > (row.fee-row.service_fee).toFixed(2)){
          //   this.$message.error('最多退款'+(row.fee-row.service_fee).toFixed(2)+'元,不包含退款安心充金额')
          //   return
          // }
          updateUrl(row.iot_sn, value).then(response => {
            if (response.code == 200) {
              this.$notify.success({
                title: '成功',
                message: '已升级 请过2分钟后重试',
                type: 'success',
                duration: 2000
              })
            } else {
              this.$notify.error({
                title: '失败',
                message: response.msg,
                duration: 2000
              })
            }
          })
        });
      }else if(row.channel == 12){
        this.$prompt('固件路径', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputValue: '/device/eBIKE-ML307R-P12-Upgradev1.01.024.bin'
        }).then(({value}) => {
          // if(value > (row.fee-row.service_fee).toFixed(2)){
          //   this.$message.error('最多退款'+(row.fee-row.service_fee).toFixed(2)+'元,不包含退款安心充金额')
          //   return
          // }
          updateUrl(row.iot_sn, value).then(response => {
            if (response.code == 200) {
              this.$notify.success({
                title: '成功',
                message: '已升级 请过2分钟后重试',
                type: 'success',
                duration: 2000
              })
            } else {
              this.$notify.error({
                title: '失败',
                message: response.msg,
                duration: 2000
              })
            }
          })
        });
      }else{
        this.$prompt('固件路径', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputValue: '/device/eBIKE-ML307R-P02-Upgradev26D05.bin'
        }).then(({value}) => {
          // if(value > (row.fee-row.service_fee).toFixed(2)){
          //   this.$message.error('最多退款'+(row.fee-row.service_fee).toFixed(2)+'元,不包含退款安心充金额')
          //   return
          // }
          updateUrl(row.iot_sn, value).then(response => {
            if (response.code == 200) {
              this.$notify.success({
                title: '成功',
                message: '已升级 请过2分钟后重试',
                type: 'success',
                duration: 2000
              })
            } else {
              this.$notify.error({
                title: '失败',
                message: response.msg,
                duration: 2000
              })
            }
          })
        });
      }
    },
    signalList(row) {
      this.now_sn = row.sn
      this.signalDraw = true
      signalList(row.id).then(response => {
        this.signalData = response.data
      })
    },
    batchShow() {
      this.dialogBatchVisible = true
    },
    showCharge(id) {
      this.showChargeVisible = true
      chargeDetail(id).then(response => {
        this.now_charge = response.data
      })
    },
    batchChange() {
      if (this.checkedIds.length <= 0) {
        this.$message.info('请先选中要回传的数据')
        return ''
      }
      let json = JSON.stringify(this.checkedIds)
      batchChange(json, this.batch_distributor_id).then(response => {
        if (response.code == 200) {
          this.dialogBatchVisible = false
          this.$notify.success({
            title: '成功',
            message: response.msg,
            type: 'success',
            duration: 2000
          })
          this.getList()
        } else {
          this.$notify.error({
            title: '失败',
            message: response.msg,
            duration: 2000
          })
        }
      })
      // let search = JSON.stringify(this.listQuery)
      // window.open('/api/excel/export_sign?data=' + json+'&search='+search)
    },
    handleCheckedIdsChange(value) {
      let checkedCount = value.length
      this.checkAll = checkedCount === this.idOptions.length
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.idOptions.length
    },
    handleCheckAllChange(val) {
      this.checkedIds = val ? this.idOptions : []
      this.isIndeterminate = false
    },
    handleCommand({row, type}) { // 解构参数对象
      switch (type) {
        case 'reset':
          this.reset(row.id)
          break
        case 'readParams':
          this.readParams(row.id)
          break
        case 'updateParams':
          this.updateParams(row)
          break
        case 'startPort':
          this.startPort(row)
          break
        case 'unbind':
          this.unbind(row)
          break
        default:
          this.showPort(row)
          break
      }
    },
    readParams(id) {
      readParams(id).then(response => {
        if (response.code == 200) {
          this.$notify.success({
            title: '读取配置提示',
            message: response.msg,
            offset: 100
          })
          this.getList()
        } else {
          this.$notify.info({
            title: '读取配置提示',
            message: response.msg,
            offset: 100
          })
        }
      })
    },
    unbind(row){
      this.$confirm('确认要恢复出厂设置？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        unbind(row.id).then(response => {
          // this.list.unshift(this.temp)
          if (response.code == 200) {
            this.$notify.success({
              title: '成功',
              message: response.msg,
              type: 'success',
              duration: 2000
            })
            this.resetTemp()
            this.getList()
          } else {
            this.$notify.error({
              title: '失败',
              message: response.msg,
              duration: 2000
            })
          }
        })
      }).catch(() => {

      })
    },
    updateParams(row) {
      this.dialogParamsVisible = true
      this.paramsTemp = {
        iot_sn: row.iot_sn,
        sn: row.sn,
        coin_min: row.coin_min,
        card_min: row.card_min,
        coin_elec: row.coin_elec,
        card_elec: row.card_elec,
        cst: row.cst,
        power_max_1: row.power_max_1,
        power_max_2: row.power_max_2,
        power_max_3: row.power_max_3,
        power_max_4: row.power_max_4,
        power_2_time: row.power_2_time,
        power_3_time: row.power_3_time,
        power_4_time: row.power_4_time,
        sp_rec_mon: row.sp_rec_mon,
        sp_full_empty: row.sp_full_empty,
        full_power_min: row.full_power_min,
        full_charge_time: row.full_charge_time,
        elec_time_first: row.elec_time_first
      }
    },
    resetPort() {
      this.portTemp = {
        sn: '',
        port: '',
        minutes: 0,
        fee: 0
      }
      this.dialogPortVisible = false
    },
    submitPort() {
      this.portTemp.sn = this.now_port_sn
      this.portTemp.port = this.now_submit_port
      startPort(this.portTemp).then(response => {
        if (response.code == 200) {
          this.$notify.success({
            title: '开启成功',
            message: response.msg,
            offset: 100
          })
          this.resetPort()
        } else {
          this.$notify.info({
            title: '开启失败',
            message: response.msg,
            offset: 100
          })
        }
      })
    },
    submitParams() {
      updateParams(this.paramsTemp).then(response => {
        if (response.code == 200) {
          this.$notify.success({
            title: '更新配置提示',
            message: response.msg,
            offset: 100
          })
          this.getList()
        } else {
          this.$notify.info({
            title: '更新配置提示',
            message: response.msg,
            offset: 100
          })
        }
      })
    },
    resetParams() {
      this.paramsTemp = {
        iot_sn: '',
        sn: '',
        coin_min: 0,
        card_min: 0,
        coin_elec: 0,
        card_elec: 0,
        cst: 0,
        power_max_1: 0,
        power_max_2: 0,
        power_max_3: 0,
        power_max_4: 0,
        power_2_time: 0,
        power_3_time: 0,
        power_4_time: 0,
        sp_rec_mon: 1,
        sp_full_empty: 1,
        full_power_min: 0,
        full_charge_time: 0,
        elec_time_first: 1
      }
      this.dialogParamsVisible = false
    },
    reset(id) {
      this.$confirm('确认要复位吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        reset(id).then(response => {
          // this.list.unshift(this.temp)
          if (response.code == 200) {
            this.$notify.success({
              title: '成功',
              message: response.msg,
              type: 'success',
              duration: 2000
            })
            this.resetTemp()
            this.getList()
          } else {
            this.$notify.error({
              title: '失败',
              message: response.msg,
              duration: 2000
            })
          }
        })
      }).catch(() => {

      })
    },
    startPort(port) {
      this.now_submit_port = port
      this.dialogPortVisible = true
    },
    showPort(row) {
      if (row.port_status) {
        this.now_port_status = row.port_status
      } else {
        this.now_port_status = []
      }
      this.now_port_sn = row.sn
      this.portDrawer = true

    },
    getDistributor(station_id) {
      getDistributor(station_id).then(response => {
        this.edit_distributor_id = response.data.distributor_id
        this.editStation(response.data.distributor_id)
      })
    },
    listDistributor(station_id) {
      getDistributor(station_id).then(response => {
        this.selectParent = response.data.distributor_id
        this.getStation(response.data.distributor_id)
      })
    },
    getStation(distributor_id) {
      if (!distributor_id) {
        if (Array.isArray(this.selectParent)) {
          var distributor_id = this.selectParent[this.selectParent.length - 1];
        } else {
          if (this.selectParent) {
            var distributor_id = this.selectParent
          } else {
            var distributor_id = ''
          }
        }
      }
      selectStation(distributor_id).then(response => {
        this.stationList = response.data
      })
    },
    showQr(row) {
      this.now_sn = row.sn
      this.now_chanel = row.channel
      this.now_port = 1
      this.dialogImgVisible = true
      this.getSnImg()
      this.getPortImg(1)
    },
    getSnImg() {
      getQrImg(this.now_sn).then(response => {
        if (response.code == 200) {
          this.sn_image = response.data.base
        }
      })
    },
    getPortImg() {
      let sn = this.now_sn + '-' + this.now_port
      getQrImg(sn).then(response => {
        if (response.code == 200) {
          this.port_image = response.data.base
        }
      })
    },
    submitUpload() {
      this.$refs.upload.submit()
    },
    handleExceed(files, fileList) {
      // this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    excelSuccess(file, fileList) {
      if (file.code == 200) {
        this.$message.success('导入成功')
        this.getList()
      } else {
        this.$message.info(file.msg)
      }
      this.fileList = []
    },
    handlePreview(file) {

    },
    handleRemove(file, fileList) {

    },
    changeStatus(val, id) {
      changeStatus(val, id).then(response => {
        this.$notify.success({
          title: '消息提示',
          message: response.msg,
          offset: 100
        })
        this.getList()
      })
    },
    getSelector() {
      all('all').then(response => {
        this.distributorsList = response.data
      })
    },
    increase() {
      this.temp.rate += 5;
      if (this.temp.rate > 100) {
        this.temp.rate = 100;
      }
    },
    decrease() {
      this.temp.rate -= 5;
      if (this.temp.rate < 0) {
        this.temp.rate = 0;
      }
    },
    handleAddrChange(e) {
      // 获取当前选中节点的数组
      let addrNode = this.$refs['cascaderAddr'].getCheckedNodes()[0]
      let addrText = addrNode.pathLabels
      this.temp.province_name = addrText[0]
      this.temp.city_name = addrText[1]
      this.temp.area_name = addrText[2]
    },
    handleDistributorsChange(e) {
      this.editStation()
    },
    editStation(distributor_id) {
      if (!distributor_id) {
        if (this.edit_distributor_id && this.edit_distributor_id.length > 0) {
          var distributor_id = JSON.stringify(this.edit_distributor_id)
        } else {
          var distributor_id = ''
        }
      }
      this.temp.station_id = ''
      selectStation(distributor_id).then(response => {
        this.stationList1 = response.data
      })
    },
    cropSuccess(resData) {
      this.imagecropperShow = false
      this.imagecropperKey = this.imagecropperKey + 1
      this.temp.avatar = resData.url
    },
    close() {
      this.imagecropperShow = false
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },

    getList() {
      if (Array.isArray(this.selectParent)) {
        this.listQuery.distributor_id = this.selectParent[this.selectParent.length - 1];
      } else {
        if (this.selectParent) {
          this.listQuery.distributor_id = this.selectParent
        } else {
          this.listQuery.distributor_id = ''
        }
      }
      if (this.listQuery.distributor_id) {
        this.getStation()
      }
      this.listLoading = true
      getList(this.listQuery).then(response => {
        this.list = response.data.list
        this.total = response.data.total
        this.info = response.data.info
        this.listLoading = false
        this.idOptions = []
        this.checkedIds = []
        for (var i in this.list) {
          this.idOptions[i] = this.list[i].id
        }
      })
    },
    resetForm() {
      this.dialogFormVisible = false
    },
    async handleCreate() {
      this.resetTemp()
      // this.getSelector()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.temp.distributors = this.edit_distributor_id
          create(this.temp).then(response => {
            // this.list.unshift(this.temp)
            this.dialogFormVisible = false
            if (response.code == 200) {
              this.$notify.success({
                title: '成功',
                message: response.msg,
                type: 'success',
                duration: 2000
              })
              this.resetTemp()
              this.getList()
            } else {
              this.$notify.error({
                title: '失败',
                message: response.msg,
                duration: 2000
              })
            }
          })
        }
      })
    },
    async handleUpdate(row) {
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.edit_distributor_id = []
      // await this.getSelector()
      if (row.station_id == 0) {
        row.station_id = ''
      }
      console.dir(row.child_distributor_id)
      if (row.child_distributor_id > 0) {
        this.edit_distributor_id.push(row.child_distributor_id)
      }
      if (row.child_distributor_id) {
        await this.editStation(row.child_distributor_id)
      } else {
        if (row.distributor_id) {
          await this.editStation(row.distributor_id)
        }
      }
      this.temp = Object.assign({}, row) // copy obj
      this.temp.station_id = row.station_id
      await setTimeout(() => {
        this.temp.station_id = row.station_id
      }, 400);
      this.$nextTick(() => {
        this.$refs['dataForm'].clearValidate()
      })
    },
    del(id) {
      this.$confirm('确认要删除该条数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del(id).then(response => {
          // this.list.unshift(this.temp)
          if (response.code == 200) {
            this.$notify.success({
              title: '成功',
              message: response.msg,
              type: 'success',
              duration: 2000
            })
            this.resetTemp()
            this.getList()
          } else {
            this.$notify.error({
              title: '失败',
              message: response.msg,
              duration: 2000
            })
          }
        })
      }).catch(() => {

      })
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        sn: '',
        iot_sn: '',
        channel: '',
        station_id: '',
        is_refund: 0,
        // is_fault:0,
        distributors: '',
        is_active: 1,
        is_new: 0,
        is_disabled: 0,
        speed:100
      }
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}

.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
<style scoped>
.avatar {
  width: 200px;
  height: 200px;
  border-radius: 50%;
}
</style>
<style lang="scss" scoped>
@import "~@/styles/mixin.scss";

.createPost-container {
  position: relative;

  .createPost-main-container {
    padding: 40px 45px 20px 50px;

    .postInfo-container {
      position: relative;
      @include clearfix;
      margin-bottom: 10px;

      .postInfo-container-item {
        float: left;
      }
    }
  }

  .word-counter {
    width: 40px;
    position: absolute;
    right: 10px;
    top: 0px;
  }
}

.article-textarea ::v-deep {
  textarea {
    padding-right: 40px;
    resize: none;
    border: none;
    border-radius: 0px;
    border-bottom: 1px solid #bfcbd9;
  }
}
</style>
